package com.wyp168.jse.face.question;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.stream.Collectors;

/**
 * @ClassName RandomOdds
 * @Title TODO
 * @Description TODO
 * @Author wyp168
 * @Date 2023/3/1 21:41
 */
public class RandomOdds {
    public static void main(String[] args) {
        RandomOdds randomOdds = new RandomOdds();
        // 通过模拟数据库表数据，来实现随机概率函数
        Map<Long, Integer> map = new HashMap<>();
        map.put(1L, 5);
        map.put(2L, 8);
        map.put(3L, 6);
        map.put(4L, 10);
        map.put(5L, 8);
        map.put(6L, 7);
        map.put(7L, 9);
        for(;;) {
            List<Object> result = map.values().stream().map(randomOdds::randomMark).collect(Collectors.toList());
            System.out.println(result);
        }
    }

    Random random = new Random(100);
    public Integer randomMark(Integer mark) {
        Integer result = 0;
        int nextVal = random.nextInt();
        switch (mark) {
            case 5:
                if (nextVal >= 50) {
                    result ++;
                }
                break;
            case 6:
                if (nextVal < 25) {
                    result ++;
                } else if (nextVal < 50) {
                    result --;
                }
                break;
            case 7:
                if (nextVal < 25) {
                    result ++;
                } else if (nextVal < 50) {
                    result -= 2;
                }
                break;
            case 8:
                if (nextVal < 25) {
                    result += 2;
                } else if (nextVal < 50) {
                    result --;
                }
                break;
            case 9:
                if (nextVal < 25) {
                    result --;
                } else if (nextVal < 50) {
                    result ++;
                }
                break;
            case 10:
                if (nextVal < 50) {
                    result --;
                }
                break;
            default:
                throw new RuntimeException("您录入的分数有误");
        }
        return mark + result;
    }
}
